<template>
	<!-- <view class="product-view"> -->
	<view class="uni-product-list">
		<view class="uni-product" v-for="(item,index) in productList" :key="index" @click="order(item)">
			<view class="image-view">
				<image v-if="renderImage" class="uni-product-image" :src="item.image"></image>
			</view>
			<view class="uni-product-text">
				<view class="uni-product-title">{{item.title}}</view>
				<view class="uni-product-price">
					<view>
						<text class="uni-product-price-favour">￥{{item.originalPrice}}</text>
						<text class="uni-product-price-original">￥{{item.favourPrice}}</text>
					</view>
					<text class="uni-product-tip">{{item.tip}}</text>
				</view>
			</view>
		</view>
	</view>

	<!-- </view> -->
</template>

<script>
	import goods from './good.js'
	export default {
		data() {
			return {
				productList: [],
				renderImage: false
			}
		},
		onLoad() {
			// this.getList();
			// console.log(goods.data.goodslist)
			// this.productList = goods.data.goodslist
			// this.renderImage = true;
		},
		mounted() {
			// console.log(goods.data.goodslist)
			this.productList = goods.data.goodslist
			this.renderImage = true;
		},
		methods: {
			order(item) {
				console.log('item', item)
				// getApp().globalData.userInfo.option = orderId
				uni.navigateTo({
					url: `/pages/details/index?id=${item.tip}`
				})
			}
			// getList() {
			//   uni.request({
			//     url: 'http://localhost:3000/goods',
			//     success: (res) => {
			//       console.log(res.data);
			//       this.productList = res.data.goodslist;
			//     }
			//   });
			// }
		},

	}
</script>

<style scoped lang="scss">
	.uni-product-list {
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx 10rpx 0 10rpx;
		background-color: #eee;
	}

	.uni-product {
		flex: 0.5;
		margin: 0 10rpx;
		margin-bottom: 20rpx;
		background-color: #fff;
		border-radius: 12rpx;

		.image-view {
			text-align: center;

			.uni-product-image {
				width: 710rpx;
				height: 310rpx;
			}
		}

		.uni-product-text {
			padding: 20rpx;
		}

		.uni-product-title {
			font-size: 30rpx;
			color: #333;
			// 英文换行
			word-break: break-all;
			// 只显示两行文本
			text-overflow: -o-ellipsis-lastline;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			line-clamp: 2;
			-webkit-box-orient: vertical;
		}

		.uni-product-price {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 4rpx;

			.uni-product-price-favour {
				font-size: 26rpx;
				color: #999;
				text-decoration: line-through;
			}

			.uni-product-price-original {
				font-size: 26rpx;
				color: red;
			}

			.uni-product-tip {
				display: flex;
				align-items: center;
				padding: 4rpx 10rpx;
				font-size: 24rpx;
				color: #fff;
				background-color: red;
				border-radius: 6rpx;
			}
		}
	}
</style>
